import React from 'react';
import { Route } from 'react-router';
import _ from 'lodash';
import cookie, { Cookies } from 'react-cookie';
import App from './app';

const defaultReplace = (replace, url)=>{
  const asgardTree = window.__INIT_STATE__.asgardTree[0].resourceBos[0].resourceBos;
  const find = _.findIndex(asgardTree, (tree)=>{
    return tree.url&&_.endsWith(tree.url, url)
  })
  if(find < 0){
    replace(asgardTree[0].url.split('#')[1])
  }
}

const routes = [{
		path: '/',
    component: App,
    indexRoute: {
      component: require('page/home'),
      onEnter: (nextState, replace)=>{ 
        const isTeacher = cookie.load('isTeacher');
        if(isTeacher&&isTeacher == '1'){
          replace('/daoshi/interview');
        }
      }
    },
    childRoutes: [
      {
        path: 'demo',
        component: require('page/demo')
      },
      {
        path: 'login',
        component: require('page/login')
      },
      {
        path: 'register',
        component: require('page/register')
      },
      {
        path: 'signin',
        component: require('page/signin')
      },
      {
        path: 'experience',
        component: require('page/experience/index')
      },
      {
        path: 'experience/:id',
        component: require('page/experience/msg')
      },
      {
        path: 'school',
        component: require('page/school/index')
      },
      {
        path: 'schoolAddress/:countryId',
        component: require('page/school/index')
      },
      {
        path: 'school/:id',
        component: require('page/school/msg')
      },
      {
        path: 'activity',
        component: require('page/activity/index')
      },
      {
        path: 'activity/:id',
        component: require('page/activity/msg')
      },
      {
        path: 'teacher',
        component: require('page/teacher/index')
      },
      {
        path: 'teacher/:id',
        component: require('page/teacher/msg')
      },
      {
        path: 'question',
        component: require('page/question/index')
      },
      {
        path: 'question/:id',
        component: require('page/question/msg')
      },
      {
        path: 'interview',
        component: require('page/interview/index')
      },
      {
        path: 'interview/:id',
        component: require('page/interview/msg')
      },
      {
        path: 'course',
        component: require('page/course/index')
      },
      {
        path: 'course/:id',
        component: require('page/course/msg')
      },
      {
        path: 'testing',
        component: require('page/testing/index')
      },
      {
        path: 'testing/:id',
        component: require('page/testing/msg')
      },
      {
        path: 'plan/submit',
        component: require('page/plan/submit')
      },
      {
        path: 'zone/index',
        component: require('page/zone/index')
      },
      {
        path: 'zone/plan',
        component: require('page/zone/plan')
      },
      {
        path: 'zone/question',
        component: require('page/zone/question')
      },
      {
        path: 'zone/teacher',
        component: require('page/zone/teacher')
      },
      {
        path: 'zone/interview',
        component: require('page/zone/interview')
      },
      {
        path: 'chat/:id',
        component: require('page/chat/index')
      },
      {
        path: 'daoshi/login',
        component: require('page/daoshi/login')
      },
      {
        path: 'daoshi/register',
        component: require('page/daoshi/register')
      },
      {
        path: 'daoshi/interview',
        component: require('page/daoshi/interview')
      }
    ]
	},
	{
		path: '*',
		component: require('page/NoMatch')
	}
]
export default routes;
